<template>
  <div>
      <h2>我是首页</h2>
      <div>我是首页的内容</div>
      <router-link to="/home/news">新闻</router-link>
      <router-link to="/home/message">消息</router-link>
      <router-view></router-view>
  </div>
</template>

<script>
export default {
  name:'home',
  data() {
    return {
      path:'/home/news'
    }
  },
  activated() {
    console.log('hoem被激活');
    this.$router.push(this.path);
  },
  deactivated() {
    console.log('home休眠了');
  },
  beforeRouteLeave (to, from, next) {
    //实现用户离开首页,再次回到首页的时候,可以回到以前停留的子组件内
    console.log(to,from,from.path);
    this.path = from.path;
    next();
  }
}
</script>

<style>
</style>
